package com.party.core.service.count.impl;

import com.google.common.base.Strings;
import com.party.core.model.crowdfund.Project;
import com.party.core.service.count.IModuleCountService;
import com.party.core.service.crowdfund.IProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 众筹统计接口实现
 * Created by wei.li.
 *
 * @date 2017/12/22 0022
 * @time 11:27
 */

@Service
@Component(value = "projectCountService")
public class ProjectCountService implements IModuleCountService {

    @Autowired
    private IProjectService projectService;

    Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 增加众筹浏览量
     * @param id 业务编号
     */
    @Override
    public void addViewNum(String id) {
        if (!Strings.isNullOrEmpty(id)){
            Project project = projectService.get(id);
            if (null != project){
                logger.info("project的信息 改之前的：projectId：{}；viewNum：{}", project.getId(), project.getViewNum());
                project.setViewNum(project.getViewNum() + 1);
                logger.info("project的信息 改之后的：projectId：{}；viewNum：{}", project.getId(), project.getViewNum());
                projectService.update(project);
            }
        }
    }
}
